﻿/// 习题9.3_八皇后 <http://t.cn/Ai0uOazs>
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>//or string.h //memset in here
using namespace std;

const int MAXN = 10 + 2;

bool visit[MAXN];
vector<int> answer;

bool valid(int x, int y, vector<pair<int, int>> sequence)
{
    for (int i = 0; i < sequence.size(); i++)
    {
        if (abs(sequence[i].first - x) ==
            abs(sequence[i].second - y))
        {
            return false;
        }
    }
    return true;
}

void DFS(int x, vector<pair<int, int> >sequence)
{
    if (sequence.size() == 8)
    {
        int num = 0;
        for (int i = 0; i < 8; i++)
        {
            num *= 10;
            num += sequence[i].second;
        }
        answer.push_back(num);
        return;
    }
    else
    {
        for (int y = 1; y <=8; y++)
        {
            if (visit[y] || !valid(x,y,sequence))
            {
                continue;
            }
            visit[y] = true;
            sequence.push_back(pair<int, int>(x, y));
            DFS(x + 1, sequence);
            visit[y] = false;
            sequence.pop_back();
        }
    }
    return;
}

int main() {
    memset(visit, false, sizeof(visit));
    vector<pair<int, int>> sequence;
    //x从1开始,表示起始点为1,同时sequence设置大小为8,表示终止点为8
    DFS(1, sequence);//x范围是1~8
    int n;
    while (cin >> n)
    {
        cout << answer[(long long)n - 1] << endl;//容器内部是0~91序号
        cout << answer[(long long)n - 1] << endl;
    }
}